package com.zxy.zxyroom.dao

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Query
import androidx.room.Transaction
import com.zxy.zxyroom.empty.TearchBean
import com.zxy.zxyroom.empty.TearchWithStudent

/**
 * Created by zxy on 2020/9/15 20:07
 * ******************************************
 * *
 * ******************************************
 */
@Dao
interface TeacherDao : BaseDao<TearchBean> {
    @Query("select * from tearcher")
    fun queryAll(): MutableList<TearchBean>
    //异步查询
    @Query("select * from tearcher")
    fun queryLiveDataAll(): LiveData<MutableList<TearchBean>>
    //单个查询
    @Query("select * from tearcher where t_id = :tearcherId")
    fun queryId(tearcherId: Int): TearchBean

    //排序查询
    @Query("select * from tearcher order by t_id desc ")
    fun queryOrderByDesc(): MutableList<TearchBean>

    //将一组参数传递给查
    @Query("SELECT * FROM tearcher WHERE t_id IN (:tearchId)")
    fun loadUsersFromRegions(tearchId: List<String>): List<TearchBean>

    //一对多
    @Transaction
    @Query("select * from tearcher")
    fun queryTearchWithStudent():List<TearchWithStudent>

    @Query("delete from tearcher")
    fun deleteAll():Int

    //模糊搜索
    @Query("select * from tearcher where t_id like '%' || :pName || '%' ORDER BY t_year Desc")
    suspend fun queryLikePname(pName: String): MutableList<TearchBean>

    //左连接查询
//    @Query(
//        "select * from Cart cart" +
//                "left join Bed bed on (bed.b_id=c_bed_id)" +
//                "where c_user_id=:userId order by c_modify_time Desc"
//    )
//    fun queryUserToBedCartList(userId: String): LiveData<MutableList<CartBean>>

}